# -*- coding: utf-8 -*-
from PhysicObject import *

class Slope(PhysicObject):
    images = load_image([['images/low_slope_right_1.png', 'images/low_slope_right_2.png'],
                         ['images/low_slope_left_1.png', 'images/low_slope_left_2.png']])
    LEFT = 0
    RIGHT = 1

    FIRST = 0
    SECOND = 1

    def __init__(self, world, x, y, direction, part):
        self.direction = direction
        self.part = part
        self.world = world
        bodyDef = box2d.b2BodyDef()
        bodyDef.position = (x, y)
        bodyDef.userData = self
        self.body = self.world.CreateBody(bodyDef)
        shapeDef = box2d.b2PolygonDef()
        if self.direction is Slope.RIGHT and self.part is Slope.FIRST:
            shapeDef.setVertices( [ (-2.2, 2.2), (2.2, 0.0), (2.2, 2.2) ] )
        elif self.direction is Slope.RIGHT and self.part is Slope.SECOND:
            shapeDef.setVertices( [ (-2.2, 2.2), (-2.2, 0.0), (2.2, -2.2), (2.2, 2.2) ] )
        elif self.direction is Slope.LEFT and self.part is Slope.FIRST:
            shapeDef.setVertices( [ (-2.2, 0.0), (2.2, 2.2), (-2.2, 2.2) ] )
        elif self.direction is Slope.LEFT and self.part is Slope.SECOND:
            shapeDef.setVertices( [ (-2.2, -2.2), (2.2, 0.0), (2.2, 2.2), (-2.2, 2.2) ] )
       
        self.body.CreateShape(shapeDef)
       
    def draw( self, surface, offset_x=0, offset_y=0 ):
        offset_x = 25 
        offset_y = 25

        pos = self.body.GetPosition()

        surface.blit(self.images[self.direction][self.part],
                     (int(pos.x*10)-offset_x, int(pos.y*10)-offset_y))

    def sleeping( self):
        return self.body.IsSleeping()

    def isAllowSleep(self):
        """Indica si tiene permitido dormirse el objeto"""
        pass

    def destroy( self):
        """Destruye el objeto """
        self.body.DestroyShape (self.shape)
